/*
 * CS 567 GUI - Semester Project - "DecisionLists"
 * Jason Frank
 * Spring 2011
 *
 * This File:  Main application class.
 */

package Decision_Lists;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.*;

/*
 * Main application class (brings everything together).
 */
public class DL_App {

  // Constructor
  public DL_App() throws IOException, Exception {

    //UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    // Get a Model
    DL_Model model = new DL_Model();

    // Get new Views

    AddItemView addItemView = new AddItemView(model);

    AddItemForm addItemForm = new AddItemForm(model);

    HeaderView header    = new HeaderView(model, addItemForm);

//    JPanel footer       = new Add_Edit_View(model);
                                                     

    // <editor-fold defaultstate="collapsed" desc="Manually adding list items">
    ////////////////////////////////////////////////////
    //// TEMP: Just manually making a new list item. TODO: remove this?
    // ITEM 1 //
    List_Item_Data item = new List_Item_Data();
    item.setName("Cabin In Woods");
    item.setPrice(500000);
    item.setSummary("A neat little getaway nestled in the old woods of Tremont.  You may hear the faint"
            + " sound of the old company store ghosts as you relax on your back porch.");
    item.setMainPic("media/CabinInWoods1.jpg");
    item.setLocationPic("media/CabinInWoods1LOCATION.PNG");


    // Add Pros
    List_Item_Data.ProCon pro = item.new ProCon();
    pro.setMainPhrase("Peacefull");
    pro.addDetail("No more cranky neighbors.  See the comments by the other owners in the "
            + "neighborhood at: www.lonelypines.com/myneighborhood");
    pro.addDetail("Loons on the water... nothing like that sound.");
    item.addPro(pro);

    pro = item.new ProCon();
    pro.setMainPhrase("Affordable");
    pro.addDetail("Half the cost of the place that's close to my work!");
    pro.addDetail("Much lower property taxes.");
    pro.addDetail("No city water bill.");
    item.addPro(pro);

    pro = item.new ProCon();
    pro.setMainPhrase("Scenic");
    pro.addDetail("View of the Little Pigeon River from back porch.");
    pro.addDetail("Early morning \"smoke\" passes through this valley.");
    item.addPro(pro);

    // Add Cons
    List_Item_Data.ProCon con = item.new ProCon();
    con.setMainPhrase("Inconvenient");
    con.addDetail("One-and-a-half hour drive to work each way.  Not only that, but its all "
            + "hair-pin curves through treacherous terrain.");
    item.addCon(con);

    con = item.new ProCon();
    con.setMainPhrase("Outhouse only");
    con.addDetail("The only \"toilet\" happens to be 40 yards outside the main house..."
            + "in a house of it's own.");
    con.addDetail("Werewolves are said to roam that area at night!");
    item.addCon(con);

    model.addNewItem(item);

      // <editor-fold defaultstate="collapsed" desc="ITEM 2">
        // ITEM 2 //
    
      item = new List_Item_Data();
      item.setName("Cabin On Mountaintop");
      item.setPrice(1000000);
      item.setSummary("A high mountaintop gettaway where the wind is the only constant element in your face."
              + "");
      item.setMainPic("media/CabinUnderSnowyMtn1.jpg");
      item.setLocationPic("media/CabinUnderSnowyMtn1LOCATION.PNG");

      // Add Pros
      pro = item.new ProCon();
      pro.setMainPhrase("Good For Your Ego");
      pro.addDetail("You could literally look down on others.");
      pro.addDetail("Self-importance is good they say.");
      item.addPro(pro);

      pro = item.new ProCon();
      pro.setMainPhrase("The View");
      pro.addDetail("Enough said.");
      item.addPro(pro);

      // Add Cons
      con = item.new ProCon();
      con.setMainPhrase("Expensive");
      con.addDetail("Put your pinky in the corner of your mouth and say (like Auston Powers) "
              + "\"One mill-i-on dollars\".");
      item.addCon(con);

      con = item.new ProCon();
      con.setMainPhrase("Small");
      con.addDetail("Only has one bedroom.");
      con.addDetail("No dining room.");
      item.addCon(con);

      model.addNewItem(item);
     
     // </editor-fold>

     // <editor-fold defaultstate="collapsed" desc="ITEM 3">
        // ITEM 3 //

      item = new List_Item_Data();
      item.setName("Row House in the City");
      item.setPrice(1500000);
      item.setSummary("A heartbeat from anything in the city, this house will make you feel like"
              + " a city slicker.");
      item.setMainPic("media/Rowhouse1.jpg");
      item.setLocationPic("media/Rowhouse1LOCATION.PNG");

      // Add Pros
      pro = item.new ProCon();
      pro.setMainPhrase("Convenient");
      pro.addDetail("Don't even need a car to get to work.");
      pro.addDetail("Grocery store is a 5 minute walk away.");
      pro.addDetail("No driveway to shovel, no grass to mow.");
      item.addPro(pro);

      // Add Cons
      con = item.new ProCon();
      con.setMainPhrase("Expensive");
      con.addDetail("Put your pinky in the corner of your mouth and say (like Auston Powers) "
              + "\"One point five mill-i-on dollars\".");
      con.addDetail("Utilities cost more than some people's mortgage payment."
              + "");
      item.addCon(con);

      con = item.new ProCon();
      con.setMainPhrase("Small");
      con.addDetail("1,200 square feet, spread out over 3 floors");
      item.addCon(con);

      con = item.new ProCon();
      con.setMainPhrase("Cranky Neighbors");
      con.addDetail("2 am, 3 am, 4 am... there's always someone to annoy you.");
      item.addCon(con);

      model.addNewItem(item);
     // </editor-fold>

     // <editor-fold defaultstate="collapsed" desc="ITEM 4">
        // ITEM 4 //

      item = new List_Item_Data();
      item.setName("Modern Marvel");
      item.setPrice(700000);
      item.setSummary("Designed by BVZ the Great, this 21st century home will be the envy of all"
              + " your neighbors.  Secret passageways complete the cool-factor.");
      item.setMainPic("media/Modern1.jpg");
      item.setLocationPic("media/Modern1LOCATION.PNG");

      // Add Pros
      pro = item.new ProCon();
      pro.setMainPhrase("Cool");
      pro.addDetail("It'll make you strut your stuff.");
      pro.addDetail("You might as well turn on some Huey Luious \"Hip to be square\".");
      item.addPro(pro);
      
      pro = item.new ProCon();
      pro.setMainPhrase("Secret Passageways");
      pro.addDetail("Great for playing hide-and-go-seek with unknowing pals.");
      pro.addDetail("One of them even leads to an underground bunker full of comic books.");
      item.addPro(pro);

      // Add Cons
      con = item.new ProCon();
      con.setMainPhrase("Trendy");
      con.addDetail("Will I still like the design in ten years?"
              + "");
      con.addDetail("Will it resell if I need to move?"
              + "");
      item.addCon(con);

      model.addNewItem(item);
     // </editor-fold>

     // <editor-fold defaultstate="collapsed" desc="ITEM 5">
     // ITEM 5 //

      item = new List_Item_Data();
      item.setName("Free Spirit Sphere");
      item.setPrice(60000);
      item.setSummary("Live like an Ewok from \"Star Wars - Return of the Jedi\" in this one-of-a-kind"
              + " treehouse.");
      item.setMainPic("media/Treehouse1.jpg");
      item.setLocationPic("media/Treehouse1LOCATION.PNG");

      // Add Pros
      pro = item.new ProCon();
      pro.setMainPhrase("Imaginative");
      pro.addDetail("Einstein said \"imagination is more important than knowledge\".");
      pro.addDetail("Live out a childhood fantasy.");
      item.addPro(pro);

      // Add Cons
      con = item.new ProCon();
      con.setMainPhrase("Unsuitable for a family");
      con.addDetail("Something tells me my wife and 4 month old are not going to go for this."
              + "");
      con.addDetail("Indoor plumbing would come in handy."
              + "");
      item.addCon(con);

      model.addNewItem(item);
     // </editor-fold>
    ///// end temp code /////////
    ////////////////////////////// </editor-fold>

    // this obj also instantiates the center views
    JPanel center_panel = new CenterPanel3(model, (DL_ViewInterface)addItemForm);

    JPanel footer           = new Add_Edit_View(model, addItemForm);

    // Now that all views have registered with the model, let header view layout itself
    //  (it needs a full list of views from the model for its comboBox)
    header.layout_my_panel();
    
    

    // Get a window to put everything in
    JFrame window = new JFrame("Decision Lists");

    // Add all views to the content pane
    window.getContentPane().add(header,       BorderLayout.NORTH);
    window.getContentPane().add(center_panel, BorderLayout.CENTER);
    window.getContentPane().add(footer,       BorderLayout.SOUTH);


    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.pack();
    window.setVisible(true);
   
  } ////////// end constructor /////////

  /*
   */
  public static void main(String[] args) {
    
    if(args.length != 0) { usage(); }

    // standard code for making all drawing occur in the event thread rather than main thread
    java.awt.EventQueue.invokeLater(new Runnable(){
      public void run() {
//        try {
          try {
            DL_App main_app = new DL_App();
          } 
          catch (Exception ex) {
            Logger.getLogger(DL_App.class.getName()).log(Level.SEVERE, null, ex);
          }
//        }
//        catch (IOException ex) { // Netbeans inserted this...
//            Logger.getLogger(DL_App.class.getName()).log(Level.SEVERE, null, ex);
//        }
      }
    });
  }  /// end main() ////////////

  private static void usage() {
    System.err.println("\nUsage:  java <app_name>\n");
    System.exit(1);
  }
  
} ///// end class DL_App ///////////////////////////////
